
#ifndef DRAWABLE_CONTAINER_H
#define DRAWABLE_CONTAINER_H

// INCLUDES ********************************************************************

#include "Drawable.h"

#include "Rectangle.h"

#include "Vector2D.h"

#include "Configuration.h"

#include "Sprite.h"

#include <vector>

#include <utility>

// FORWARD DECLARATIONS ********************************************************

namespace Meteor
{
    class Texture2D;
}

// *****************************************************************************

//! DrawableContainer
//! 
//! A graphic object that contains other graphic objects

//! The DrawableContainer contains other objects such as sprites, which them-
//! selves contain graphic information ( images, fonts etc.)
//! This is the class the user would typically inherit from for his own
//! objects that themselves contains objects

// *****************************************************************************

namespace Meteor
{

    // *************************************************************************

     //! compare Drawables via z-index
    struct DepthComparator
    {
        //! used within DrawableContainer
        bool operator()( const std::pair<Drawable*, const bool>& left,
                         const std::pair<Drawable*, const bool>& right) const
        {
            return left.first->IndexZ() < right.first->IndexZ();
        } 
    };

    // *************************************************************************

    class DrawableContainer : public Drawable
    {
        public:
            DrawableContainer( const Vector2D size=Vector2D( Meteor::Configuration::Instance().ValueForKey<Meteor::Vector2D>("Screensize").X(),
                                                             Meteor::Configuration::Instance().ValueForKey<Meteor::Vector2D>("Screensize").Y()));
            
            explicit DrawableContainer( const uint32_t zIndex, const Vector2D size=Vector2D(4, 4));
            
            virtual ~DrawableContainer();
            
            //! Add a child to this container. The container is now the owner
            //! and will manage the objects memory
            virtual void AddChild( Drawable* child, const bool takeOwnership = true);
            
            //! Removing the child will also delete it, e.g. the memory taken
            //! will be freed.
            virtual void RemoveChild( Drawable* child);
        
            //! remove all children
            void Clear();
            
            //! set position for children, too
            void SetPosition( const float x, const float y);
        
            void SetPosition( const Vector2D& newPosition);
        
            void SetSize( const Vector2D& size);
        
            const Vector2D& Size() const;
        
            virtual const float Scale() const;
            
            virtual void SetScale( const float newScale);
        
            //! children will be rotated, too
            virtual void SetRotation( const float angle);
            
            virtual const float Rotation() const;
        
            virtual void SetAlpha( const float alpha);
        
            virtual const float Alpha() const;
    
            virtual void Update( const float deltaTime);
            
            virtual void Draw() const;
    
        protected:
            typedef std::vector<std::pair<Drawable*, bool> > containerType;
        
            containerType mChildren;
        
            Vector2D mSize;
        
    }; // end of class DrawableContainer

} // end of class Meteor

#endif

